package com.xiaxiang.xiawan;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.xiaxiang.xiawan.Home.XXARVideoActivity;

/**
 * Created by Administrator on 2017-08-08.
 */

public class FragmentBase extends Fragment{
    protected MainActivity mMainActivity;
    //private XXMainApplication mMainApplication;
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

    }

    public void onActivityCreate(Bundle bundle){
        super.onActivityCreated(bundle);
       // mMainApplication = (XXMainApplication)getActivity().getApplication();
        Log.e("login"," getActivity is "+getActivity());
        mMainActivity = (MainActivity)getActivity();
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    public void onStart(){
        super.onStart();
        mMainActivity = (MainActivity)getActivity();
    }
    public boolean isLogin(){
        Log.e("login"," mMainApplication is "+mMainActivity);
        return mMainActivity.isLogin();
    }

    public void setIsLogin(boolean is){
        mMainActivity.setIsLogin(is);
    }

    protected void startLoginActivity() {
        Intent intent = new Intent("com.xiaxiang.xiawan.login");
        intent.setPackage(getActivity().getPackageName());
        getActivity().startActivityForResult(intent, XXConfigData.LOGIN_REQUEST_CODE);
    }

    protected void showToastTips(final String tips) {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast mToast = Toast.makeText(getActivity(), tips, Toast.LENGTH_SHORT);
                mToast.show();
            }
        });
    }

    public void onViewStateRestored(Bundle bundle){
        super.onViewStateRestored(bundle);
    }
}
